//
//  LOLInformationViewController.m
//  LOLXXbox
//
//  Created by dllo on 16/1/27.
//  Copyright © 2016年 Grasstrio. All rights reserved.
//

#import "LOLInformationViewController.h"
#import "LOLInfamacell.h"
#import "LSZNetWorkTools.h"
#import <AFNetworking.h>
#import "LOLInformaModel.h"
#import "LOLEquipViewController.h"
#import "LOLTalentViewController.h"
#import "LOLRuneViewController.h"
#import "LOLSquadViewController.h"
#import "LOLSkillsViewController.h"
@interface LOLInformationViewController ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *dataSource;

@end

@implementation LOLInformationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.navigationItem.title = @"百科";
    self.view.backgroundColor = [UIColor whiteColor];
    [self createTableView];
    [self getData];
}

#pragma mark -- tableView
- (void)createTableView{
    self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    [self.tableView registerClass:[LOLInfamacell class] forCellReuseIdentifier:@"cell"];
    [self.view addSubview:self.tableView];
    self.dataSource = [NSMutableArray array];

}

- (void)getData{
    [LSZNetWorkTools getWithUrl:@"http://box.dwstatic.com/apiToolMenu.php?category=database&v=129" parameter:nil httpHeader:nil resposeType:ResponseTypeJSON success:^(id result) {
        NSArray *array = result;
        for (NSDictionary *dic in array) {
            LOLInformaModel *model = [[LOLInformaModel alloc] initWithDataSource:dic];
            [self.dataSource addObject:model];
        }
        dispatch_async(dispatch_get_main_queue(), ^{
            [self.tableView reloadData];
        });
        
    } fail:^(NSError *error) {
        NSLog(@"error");
    }];

    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataSource.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    LOLInfamacell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    cell.informaModel = self.dataSource[indexPath.row];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 50;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return CGFLOAT_MIN;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
    switch (indexPath.row) {
        case 0:
        {
            LOLEquipViewController *equipVC = [[LOLEquipViewController alloc] init];
            [self.navigationController pushViewController:equipVC animated:YES];
        }
            break;
         case 1:
        {
            LOLTalentViewController *talentVC = [[LOLTalentViewController alloc] init];
            [self.navigationController pushViewController:talentVC animated:YES];
        }
            break;
        case 2:
        {
            LOLRuneViewController *runeVC = [[LOLRuneViewController alloc] init];
            [self.navigationController pushViewController:runeVC animated:YES];
        }
            break;
        case 3:
        {
            LOLSquadViewController *squadVC = [[LOLSquadViewController alloc] init];
            [self.navigationController pushViewController:squadVC animated:YES];
        }
            break;
        case 4:
        {
            LOLSkillsViewController *skillsVC = [[LOLSkillsViewController alloc] init];
            [self.navigationController pushViewController:skillsVC animated:YES];
        }
            break;
        default:
            break;
    }
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
